package com.sundablog.service.impl.systemsetup.logSetting;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sundablog.mapper.AdminLogMapper;
import com.sundablog.pojo.AdminLog;
import com.sundablog.pojo.AdminLogExample;
import com.sundablog.pojo.AdminLogExample.Criteria;
import com.sundablog.pojo.AdminLogWithBLOBs;
import com.sundablog.result.LayUiResult;
import com.sundablog.service.systemsetup.logSetting.LogService;

/**
 * 日志实现类
 * @ClassName:  LogServiceImpl   
 * @Description:TODO(这里用一句话描述这个类的作用)   
 * @author: 哒哒 
 * @date:   2018年2月28日 下午4:13:33   
 *     
 * @Copyright: 2018 www.sundablog.com Inc. All rights reserved.
 */
@Service
public class LogServiceImpl implements LogService {

	@Autowired
	private AdminLogMapper adminLogMapper;
	
	/**
	 * 添加一条日志
	 * Title: addAdminLog   
	 * Description:    
	 * @param adminLog
	 * @return   
	 * @see com.sundablog.service.systemsetup.logSetting.LogService#addAdminLog(com.sundablog.pojo.AdminLog)
	 */
	@Override
	public int addAdminLog(AdminLogWithBLOBs adminLogWithBLOBs) {
		int i = adminLogMapper.insertSelective(adminLogWithBLOBs);
		return i;
	}

	/**
	 * 分页查询
	 * Title: findPagingQuery   
	 * Description:    
	 * @param page
	 * @param limit
	 * @return   
	 * @see com.sundablog.service.systemsetup.logSetting.LogService#findPagingQuery(int, int)
	 */
	@Override
	public LayUiResult findPagingQuery(int page, int limit) {
		PageHelper.startPage(page, limit);
		PageHelper.orderBy("log_id desc");
		AdminLogExample example = new AdminLogExample();
		List<AdminLogWithBLOBs> list = adminLogMapper.selectByExampleWithBLOBs(example);
		PageInfo<AdminLogWithBLOBs> pageInfo = new PageInfo<>(list);
		
		LayUiResult layUiResult = new LayUiResult();
		layUiResult.setCode(0);
		layUiResult.setMsg("");
		layUiResult.setCount(pageInfo.getTotal());
		layUiResult.setData(list);
		return layUiResult;
	}

}
